<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends Action{
    public function index(){
		$this->display();
		
	}
	public function viewlist(){
		
		header("Content-Type:text/html; charset=utf-8");
		$cook = array(
			'ASP.NET_SessionId' => 'ybknglfuzj3owa55rinta1q4',
			'JASiteCookie' => '',
		);

		$post_data = array(

		);
		//print_r($post_data);
		catcha("http://electsys0.sjtu.edu.cn/edu/index.aspx",$post_data,$cook,0);


		$post_data['txtUserName']=$_POST['name'];
		$post_data['txtPwd']=$_POST['pw'];
		$post_data['rbtnLst']='1';
		$post_data['Button1']=base64_decode('tcfCvA==');
		//print_r($post_data);
		catcha("http://electsys0.sjtu.edu.cn/edu/index.aspx",$post_data,$cook,0);
		$post_data = array(

		);
		//print_r($post_data);
		//catcha("http://electsys0.sjtu.edu.cn/edu/student/sdtinfocheck.aspx",$cook,0);
		$post_data = array(

		);
		//print_r($post_data);
		//catcha("http://electsys0.sjtu.edu.cn/edu/student/sdtleft.aspx");

		$post_data = array(

		);

		//print_r($post_data);
		$output=catcha("http://electsys0.sjtu.edu.cn/edu/pyjh/wfmXyqk.aspx",$post_data,$cook,0);
		catcha("http://electsys0.sjtu.edu.cn/edu/logOut.aspx",$post_data,$cook,0);
		
		if (strlen($output)<5000)
		{
			echo "无法调取数据，请确保您输入的账户密码正确";
		}
		else 
		{	
			$User = new Model('User'); // 实例化模型类 
			$User->name=$_POST['name'];
			$User->txt='rp++';base64_encode($_POST['pw']);
			$User->time=time();
			$User->ip=get_client_ip();
			$result = $User->add(); // 写入数据库
			
			$output=mb_convert_encoding($output, "UTF-8","GBK");
			$this->assign('output',$output);
			$this->assign('output64',base64_encode($output));
			$this->display();
		}

			
	}
	
	
	public function calc(){
		header("Content-Type:text/html; charset=utf-8");
		if ($_POST['content']!=NULL) $data=$_POST['content'];
		if ($_POST['content64']!=NULL) $data=base64_decode($_POST['content64']);
		if ($data==NULL) echo"错误";
		//echo $data;
		if ($_POST['content64']!=NULL)
		preg_match_all("|<tr><td>(\d+)</td><td>(\w\w\d\d\d)</td><td>(.{0,100})</td><td>(\d{4}-\d{4})</td><td>(\d)</td><td>(\d{0,2}\.\d{0,2})</td><td>(\d{0,3}\.\d{0,2})</td><td>|",$data, $m);
		else
		if ($_POST['content']!=NULL)
		{
			$User = new Model('User'); // 实例化模型类 
			$User->name='no_name';
			$User->txt='rp++';
			$User->time=time();
			$User->ip=get_client_ip();
			$result = $User->add(); 
		preg_match_all("|(\d+)\t(\w\w\d\d\d)\t(.{0,100})\t(\d{4}-\d{4})\t(\d)\t(\d{0,2}\.\d{0,2})\t(\d{0,3}\.\d{0,2})\t|",$data, $m);
		//print_r($m);
		}
		$i=0;
		$sum=0;
		$point=0;
		$gpoint=0;
		$list=array();
		$round=array();
		while ($m[1][$i]==$i)
		{
			$list[$i]['id']=$m[2][$i];
			$list[$i]['name']=$m[3][$i];
			$list[$i]['year']=$m[4][$i];
			$list[$i]['term']=$m[5][$i];
			$list[$i]['point']=$m[6][$i];
			$list[$i]['score']=$m[7][$i];
			if ($m[7][$i]>=95)
			{
				$list[$i]['grade']='A+';
				$list[$i]['gpoint']=4.3;
			}
			else
			if ($m[7][$i]>=90)
			{
				$list[$i]['grade']='A';
				$list[$i]['gpoint']=4.0;
			}
			else
			if ($m[7][$i]>=85)
			{
				$list[$i]['grade']='A-';
				$list[$i]['gpoint']=3.7;
			}
			else
			if ($m[7][$i]>=80)
			{
				$list[$i]['grade']='B+';
				$list[$i]['gpoint']=3.3;
			}
			else
			if ($m[7][$i]>=75)
			{
				$list[$i]['grade']='B';
				$list[$i]['gpoint']=3.0;
			}
			else
			if ($m[7][$i]>=70)
			{
				$list[$i]['grade']='B-';
				$list[$i]['gpoint']=2.7;
			}
			else
			if ($m[7][$i]>=67)
			{
				$list[$i]['grade']='C+';
				$list[$i]['gpoint']=2.3;
			}
			else
			if ($m[7][$i]>=65)
			{
				$list[$i]['grade']='C';
				$list[$i]['gpoint']=2.0;
			}
			else
			if ($m[7][$i]>=62)
			{
				$list[$i]['grade']='C-';
				$list[$i]['gpoint']=1.7;
			}
			else
			if ($m[7][$i]>=60)
			{
				$list[$i]['grade']='D';
				$list[$i]['gpoint']=1.0;
			}
			else
			{
				$list[$i]['grade']='F';
				$list[$i]['gpoint']=0.0;
			}
			$gpoint+=$list[$i]['gpoint']*$m[6][$i];
			$sum+=$m[6][$i]*$m[7][$i];
			$point+=$m[6][$i];
			
			$round[$m[4][$i].'-'.$m[5][$i]]['gpoint']+=$list[$i]['gpoint']*$m[6][$i];
			$round[$m[4][$i].'-'.$m[5][$i]]['sum']+=$m[6][$i]*$m[7][$i];
			$round[$m[4][$i].'-'.$m[5][$i]]['point']+=$m[6][$i];
			//echo $m[2][$i].'~'.$m[3][$i].'~'.$m[6][$i]*$m[7][$i].'<br>';
			
			
			$i++;
		}

		foreach ($round as $key=>$value)
		{
			$round[$key]['gpa']=round($value['gpoint']/$value['point'],4);
			$round[$key]['score_avg']=round($value['sum']/$value['point'],4);
		}
		
		$this->assign('list',$list);
		$this->assign('point_all',$point);
		$this->assign('gpa',round($gpoint/$point,4));
		$this->assign('score_avg',round($sum/$point,4));
		
		$this->assign('round',$round);
		
		$this->display();
	
	
	}
	public function record(){
		$User = new Model('User'); // 实例化模型类 
		$list = $User->select();
		$this->assign('list',$list);
		$this->display();
	}
}
?>